<template>
  <!-- ! 通过操作css来实现详情页的显示和隐藏 -->
    <div class="modal-mask" :class="{ hidden: !data.length }">
      <div class="modal-container">
        <div class="modal-header">
          <h3>就诊记录详情</h3>
          <span class="close-btn" @click="cancel">X</span>
        </div>
        <div class="modal-body">
          <!-- ! 拿到数据渲染详情页数据 -->
          <p><strong>就诊日期：</strong>{{ data.length ? data[0].date : 0 }}</p>
          <p><strong>医生姓名：</strong>{{ data.length ? data[0].doctor : 0}}</p>
          <p><strong>诊断结果：</strong>{{ data.length ? data[0].diagnosis : 0}}</p>
          <p><strong>处方信息：</strong>{{data.length ? data[0].prescription : 0 }}</p>
        </div>
      </div>
    </div>
  </template>
  <script>
  import Bus from '../utils/EventBus'
    export default{
      data(){
        return{
          data:[],
        }
      },
        created(){
          // ! 通过事件总线拿到兄弟组件传过来的数据
          Bus.$on('sendDetail',(detail)=>{
            this.data=detail   
          })
        },
        methods:{
          cancel(){
            // ! 点击取消按钮，清空当前数组，数组清空长度为0，详情页会隐藏
            this.data=[] 
          }
        }
    }
</script>
  <style scoped>
  .hidden{
    display: none !important;
  }
  .modal-mask {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
  }
  
  .modal-container {
    background-color: #fff;
    border-radius: 5px;
    padding: 20px;
    max-width: 500px;
  }
  
  .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  .close-btn {
    cursor: pointer;
  }
  </style>
  